﻿using System;
using System.Linq;
using System.Web.Mvc;

namespace Facebook.Web.Mvc
{
    public class FeedController : Controller
    {        
        public ActionResult Post(String id)
        {
            var ids = Configuration.TemplateBundleIds.GetCurrent(this.Request.Params["fb_sig_api_key"]);
            var templateId = ids.Single(tid => tid.Name == id);

            return this.Json(new
            {
                content = new
                {
                    feed = new
                    {
                        template_id = templateId.Id,
                        template_data = (
                            from paramKey in this.Request.Params.Keys.OfType<String>()
                            where paramKey.StartsWith("__fb_feed_")
                            select new { Name = paramKey.Replace("__fb_feed_", String.Empty), Value = this.Request.Params[paramKey] })
                                .ToDictionary(data => data.Name, data => data.Value)
                    }
                },
                method = "feedStory"
            });
        }
    }
}